<?php
namespace app\index\controller;

use think\Controller;
use app\index\model\Article;

class Index extends Controller
{
    //初始化登入
    public function _initialize()
    {
        $renderData = [
            "logined" => false, //登入状态
            "username" => "",
            "img_url" => "user_ini.svg",
        ];

        $username = session('username'); //用户名
        $id = session('id'); //id
        if ($username) {
            $renderData["logined"] = true;
            $userInFo = model('user')->get($id); //获取用户信息
            if($userInFo) {
                $renderData["username"] = $username;
                $renderData["img_url"] = $userInFo->img_url;
            }
        } else {
            $renderData["logined"] = false;
        }

        $this->assign($renderData);
    }


    //首页渲染
    public function index()
    {
        return $this->fetch();
    }

    //about_me 页面
    public function about_me()
    {
        return $this->fetch();
    }

    // 最后加的页面
    public function future()
    {
        $article = new Article();
        $articles = $article->getArticles();

        $this->assign("articles", $articles);

        return $this->fetch();
    }
}
